package com.java2007.zhangyu.restaurant.dao.impl;

import com.java2007.zhangyu.restaurant.dao.AdminDao;
import com.java2007.zhangyu.restaurant.pojo.Admin;
import com.java2007.zhangyu.restaurant.utils.JdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

/**
 * 用户持久层
 * @author zy
 * @Version
 * @date 2021/01/28
 */
public class AdminDaoImpl implements AdminDao{
    /**
     * 根据用户名查询
     * @param aName
     * @return
     * @throws Exception
     */
    @Override
    public Admin queryByAdminName(String aName) throws Exception{
        QueryRunner runner = new QueryRunner();

        String sql = "SELECT a_name aName,a_password aPassword,a_state aState,a_phone aPhone,a_email aEmail,a_role aRole,a_create_time aCreateTime,a_update_time aUpdateTime\n" +
                "FROM t_admin\n" +
                "WHERE a_name = ?";

        return runner.query(JdbcUtils.getConnection(),sql,new BeanHandler<>(Admin.class),aName);
    }
}
